package com.yuexia.yxim.client.sender;

import com.yuexia.yxim.client.protoBuilder.ChatMsgBuilder;
import com.yuexia.yxim.client.protoBuilder.LoginMsgBuilder;
import com.yuexia.yxim.common.bean.ChatMsg;
import com.yuexia.yxim.common.bean.msg.ProtoMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * LoginSender
 *
 * @author wjp
 * @date 2020/6/1
 */
@Slf4j
@Service
public class ChatSender extends BaseSender{


    /**
     * 发送消息
     * @param toUserId
     * @param message
     */
    public void sendMsg(String toUserId, String message) {
        log.info("发送消息 startConnectServer");

        ChatMsg chatMsg = new ChatMsg();
        chatMsg.setContent(message);
        chatMsg.setMsgType(ChatMsg.MSGTYPE.TEXT);
        chatMsg.setTo(toUserId);
        chatMsg.setMsgId(System.currentTimeMillis());

        ProtoMsg.Message msg = ChatMsgBuilder.buildChatMsg(chatMsg, getUser(), getSession());

        super.sendMsg(msg);
    }

    @Override
    protected void sendSucced(ProtoMsg.Message message) {
        log.info("发送成功：{}", message.getMessageRequest().getContent());
    }

    @Override
    protected void sendfailed(ProtoMsg.Message message) {
        log.info("发送失败：{}", message.getMessageRequest().getContent());
    }
}
